package com.gh.digui;

import org.junit.Test;


public class DiGui {
/*    public static void main(String[] args) {

        int num = sum(0,3);
        System.out.println(num);
    }*/

    @Test
    public void test(){

        System.out.println("-----------------------");
        System.out.println("从startnum加到endnum求和");
        System.out.println(sum(0,100));
        System.out.println("-----------------------");
        System.out.println("单个参数递归增至设定值：");
        System.out.println(diGUiSumUp(0));
        System.out.println("---------------------");
        System.out.println("单个参数递归减至设定值：");
        System.out.println(diGUiSumDown(100));
        System.out.println("---------------------");

    }

    public  int sum(int startnum, int endnum){
        int sum = 0;
        for(int i = startnum;i <= endnum;i++){
            sum += i;
        }
        return sum;
    }

    public  int diGUiSumUp(int n){
        if (n == 100){
            return n;
        }
        return n + diGUiSumUp(n+1);
    }

    public  int diGUiSumDown(int n){
        if (n == 0){
            return n;
        }
        return n + diGUiSumDown(n-1);
    }



    @Test
    public void test02(){
        System.out.println(f(10));
    }
    //已知f(0) = 1,f(1) = 4,f(n+2) = 2*f(n+1) + f(n);
    //n+2 = t,n = t - 2,f(t) = 2*f(t-1) + f(t-2)
    //其中n是大于0的整数，求f(10)
    public  int f(int n){
        if(n <= 0){
            return 1;
        }
        if (n == 1){
            return 4;
        }
        return 2*f(n-1)+f(n-2);
    }


    @Test
    public void t1(){
        System.out.println("斐波那契数列");

        System.out.println(t1(50)+"");
    }

    //1+1+2+3+5.....，每个数都是前两个数的和
    public long t1(long n){
        if(n < 1){
            return -1;
        }else if(n == 1 || n == 2){
           return 1;
       }
        return t1(n-2) + t1(n -1);
    }




}
